
#include <thread>
#include "../common/dispather.h"
#include "../client/requestor.h"
#include "../client/rpc_caller.h"
int main()
{
    auto requestor = std::make_shared<rpc::client::Requestor>();
    auto caller = std::make_shared<rpc::client::RpcCaller>(requestor);

    auto dispather = std::make_shared<rpc::dispather>();
    auto rsp_cb = std::bind(&rpc::client::Requestor::onResponse, requestor.get(), std::placeholders::_1, std::placeholders::_2);

    dispather->registerHandler<rpc::BaseMessage>(lxprpc::MType::RSP_RPC, rsp_cb);
    auto message_cb = std::bind(&rpc::dispather::onMessage, dispather.get(), std::placeholders::_1, std::placeholders::_2);
    auto client = rpc::ClientFactory::create("127.0.0.1", 9090);
    client->setMessageCallback(message_cb);
    client->connect();

    auto conn = client->connection();
    Json::Value params, result;
    params["num1"] = 11;
    params["num2"] = 22;

    bool ret = caller->call(conn, "Add", params, result);
    if (ret != false)
    {
        std::cout << "result:" << result.asInt() << std::endl;
    }
    client->shutdown();
    return 0;
}